home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / applic / ntp / depredated / ntp.3.4 / patches / patch4.Z / patch4
Encoding:
Text File  |  1991-09-29  |  36.1 KB  |  1,389 lines

  1. System: ntp version 3.4
  2. Patch #: 4
  3. Priority: 
  4. Subject:
  5.  
  6. Don't bother to create the Version file for the distribution any longer.
  7. Define SUN_FLT_BUG rather than just 'sun' to get the a fix for a floating
  8. point problem in ntpsubs; apparantly the DECSTATION 3100 also has the
  9. same problem.
  10. Removed some unused #defines.  Replaced MAXSTRATUM with NTP_INFIN per new
  11. spec.  The variable 'mode' in the peer structure has been renamed 'hmode'
  12. per the new spec.
  13. The variable 'mode' in the peer structure was renamed 'hmode'.  Add 
  14. poll_update() calls in a few places per Mills.  The receive() procedure is
  15. now table driven.  The poll_update procedure only randomized the timer
  16. when the interval changes.  If we lose synchronization, don't zap sys.stratum.
  17. Clean up the sanity_check() routine a bit.
  18. peer->mode has been renamed peer->hmode.  Drop PEER_FL_SYNC since the
  19. PEER_FL_CONFIG flag means much the same thing.
  20. Check for success sending query before trying to listen for answers.  Will 
  21. catch case of no server running and an ICMP port unreachable being returned.
  22. Add -l option to create a log scale plot of the compliance.  Fix the option
  23. handling code so that -S works again.  The drift compensation and compliance
  24. values are now scaled.
  25. From:
  26.  
  27. Description:
  28.  
  29. Repeat-By:
  30.  
  31. Fix:    From rn, say "| patch -p -N -d DIR", where DIR is your ntp source
  32.     directory.  Outside of rn, say "cd DIR; patch -p -N <thisarticle".
  33.     If you don't have the patch program, apply the following by hand,
  34.     or get patch (version 2.0, latest patchlevel).
  35.  
  36.     After patching:
  37.         make depend
  38.         make
  39.         make install
  40.  
  41.     If patch indicates that patchlevel is the wrong version, you may need
  42.     to apply one or more previous patches, or the patch may already
  43.     have been applied.  See the patchlevel.h file to find out what has or
  44.     has not been applied.  In any event, don't continue with the patch.
  45.  
  46.     If you are missing previous patches they can be obtained from me:
  47.  
  48.     Louis A. Mamakos
  49.     louie@trantor.umd.edu
  50.  
  51.     You can also get the patches via anonymous FTP from
  52.     trantor.umd.edu.
  53.  
  54. Index: patchlevel.h
  55. Prereq: 3
  56. 1c1
  57. < #define PATCHLEVEL 3
  58. ---
  59. > #define PATCHLEVEL 4
  60.  
  61. Index: Makefile
  62. *** Makefile.old    Wed Mar 29 12:47:37 1989
  63. --- Makefile    Wed Mar 29 12:47:38 1989
  64. ***************
  65. *** 1,6 ****
  66. ! # $Source: /usr/users/louie/ntp/RCS/Makefile,v $ $Revision: 3.4.1.2 $ $Date: 89/03/22 18:25:14 $
  67.   #
  68.   # $Log:    Makefile,v $
  69.   # Revision 3.4.1.2  89/03/22  18:25:14  louie
  70.   # patch3: Use new and improved RCS headers.
  71.   # 
  72. --- 1,12 ----
  73. ! # $Source: /usr/users/louie/ntp/RCS/Makefile,v $ $Revision: 3.4.1.3 $ $Date: 89/03/29 12:21:27 $
  74.   #
  75.   # $Log:    Makefile,v $
  76. + # Revision 3.4.1.3  89/03/29  12:21:27  louie
  77. + # Don't bother to create the Version file for the distribution any longer.
  78. + # Define SUN_FLT_BUG rather than just 'sun' to get the a fix for a floating
  79. + # point problem in ntpsubs; apparantly the DECSTATION 3100 also has the
  80. + # same problem.
  81. + # 
  82.   # Revision 3.4.1.2  89/03/22  18:25:14  louie
  83.   # patch3: Use new and improved RCS headers.
  84.   # 
  85. ***************
  86. *** 74,80 ****
  87.   DEFINES=
  88.   
  89.   # for Sun
  90. ! #DEFINES= -Dsun
  91.   
  92.   # for Ultrix 2.0/2.2/3.0
  93.   # don't forget to fix the broken definition of inet_addr in netdb.h
  94. --- 80,86 ----
  95.   DEFINES=
  96.   
  97.   # for Sun
  98. ! #DEFINES= -DSUN_FLT_BUG
  99.   
  100.   # for Ultrix 2.0/2.2/3.0
  101.   # don't forget to fix the broken definition of inet_addr in netdb.h
  102. ***************
  103. *** 169,178 ****
  104.       mv ntp.tar.Z /usr/ftp/pub/ntp.${VERS}/ntp-test.tar.Z
  105.   
  106.   ntp.tar.Z:    ${DIST}
  107. -     ident ${DIST} | grep Header | \
  108. -         sed -e 's/^ *.Header: //' -e 's/.\$$//' > Version
  109.       rm -f ntp.tar ntp.tar.Z
  110. !     tar cf ntp.tar Version ${DIST}
  111.       compress  ntp.tar
  112.   
  113.   
  114. --- 175,182 ----
  115.       mv ntp.tar.Z /usr/ftp/pub/ntp.${VERS}/ntp-test.tar.Z
  116.   
  117.   ntp.tar.Z:    ${DIST}
  118.       rm -f ntp.tar ntp.tar.Z
  119. !     tar cf ntp.tar ${DIST}
  120.       compress  ntp.tar
  121.   
  122.   
  123.  
  124. Index: ntp.h
  125. *** ntp.h.old    Wed Mar 29 12:47:42 1989
  126. --- ntp.h    Wed Mar 29 12:47:43 1989
  127. ***************
  128. *** 1,7 ****
  129. ! /* $Source: /usr/users/louie/ntp/RCS/ntp.h,v $ $Revision: 3.4.1.2 $ $Date: 89/03/22 18:28:18 $ */
  130.   
  131.   /*
  132.    *  $Log:    ntp.h,v $
  133.    * Revision 3.4.1.2  89/03/22  18:28:18  louie
  134.    * patch3: Use new RCS headers.
  135.    * 
  136. --- 1,12 ----
  137. ! /* $Source: /usr/users/louie/ntp/RCS/ntp.h,v $ $Revision: 3.4.1.3 $ $Date: 89/03/29 12:26:18 $ */
  138.   
  139.   /*
  140.    *  $Log:    ntp.h,v $
  141. +  * Revision 3.4.1.3  89/03/29  12:26:18  louie
  142. +  * Removed some unused #defines.  Replaced MAXSTRATUM with NTP_INFIN per new
  143. +  * spec.  The variable 'mode' in the peer structure has been renamed 'hmode'
  144. +  * per the new spec.
  145. +  * 
  146.    * Revision 3.4.1.2  89/03/22  18:28:18  louie
  147.    * patch3: Use new RCS headers.
  148.    * 
  149. ***************
  150. *** 71,79 ****
  151.   /*
  152.    *  Definitions for the masses
  153.    */
  154. - #define    MAXNAMELENGTH    80
  155.   #define    JAN_1970    2208988800    /* 1970 - 1900 in seconds */
  156. - #define    HIGH_BIT    0x80000000    /* sign bit on fixed point */
  157.   
  158.   /*
  159.    *  Daemon specific (ntpd.c)
  160. --- 76,82 ----
  161. ***************
  162. *** 100,107 ****
  163.   };
  164.   
  165.   #define    STRMCMP(a, cond, b) \
  166. !     (((a) == UNSPECIFIED ? MAXSTRATUM+1 : a) cond \
  167. !      ((b) == UNSPECIFIED ? MAXSTRATUM+1 : (b)))
  168.   
  169.   
  170.   /*
  171. --- 103,110 ----
  172.   };
  173.   
  174.   #define    STRMCMP(a, cond, b) \
  175. !     (((a) == UNSPECIFIED ? NTP_INFIN+1 : a) cond \
  176. !      ((b) == UNSPECIFIED ? NTP_INFIN+1 : (b)))
  177.   
  178.   
  179.   /*
  180. ***************
  181. *** 109,114 ****
  182. --- 112,118 ----
  183.    */
  184.   #define    NTP_VERSION    1
  185.   #define    NTP_PORT    123    /* for ref only (see /etc/services) */
  186. + #define    NTP_INFIN    15
  187.   #define    NTP_MAXAGE    86400
  188.   #define    NTP_MAXSKW    0.01    /* seconds */
  189.   #define    NTP_MINDIST    0.02    /* seconds */
  190. ***************
  191. *** 125,131 ****
  192.   #define    PEER_MAXDISP    64.0    /* Maximum dispersion  */
  193.   #define    PEER_THRESHOLD    0.5    /* dispersion threshold */
  194.   #define    PEER_FILTER    0.5    /* filter weight */
  195. - #define    PEER_SELECT    0.75    /* select weight */
  196.   
  197.   #if    XTAL == 0
  198.   #define    PEER_SHIFT    4
  199. --- 129,134 ----
  200. ***************
  201. *** 136,144 ****
  202.   #define    NTP_WINDOW_SHIFT_MASK 0xff
  203.   #define    PEER_SHIFT_MASK    0xff    /* 2^PEER_SHIFT - 1 */
  204.   
  205. - #define    NTP_MAXDELAY    65536.0    /* Maximum dispersion seconds*/
  206.   /*
  207.    *  5.1 Uniform Phase Adjustments
  208.    *  Clock parameters
  209. --- 139,144 ----
  210. ***************
  211. *** 261,267 ****
  212.    */
  213.   #define    UNSPECIFIED    0
  214.   #define    PRIM_REF    1    /* radio clock */
  215. - #define    MAXSTRATUM    15
  216.   #define    INFO_QUERY    62    /* **** THIS implementation dependent **** */
  217.   #define    INFO_REPLY    63    /* **** THIS implementation dependent **** */
  218.   
  219. --- 261,266 ----
  220. ***************
  221. *** 277,283 ****
  222.       int    flags;            /* local flags */
  223.   #define    PEER_FL_CONFIG        1
  224.   #define    PEER_FL_AUTHENABLE    2
  225. - #define    PEER_FL_SYNC        0x1000    /* allowed synchronize to this peer */
  226.   #define    PEER_FL_BCAST        0x2000    /* broadcast peer */
  227.   #define    PEER_FL_SELECTED    0x8000    /* actually used by query routine */
  228.   
  229. --- 276,281 ----
  230. ***************
  231. *** 284,290 ****
  232.       int    sock;            /* index into sockets to derive
  233.                          peer.dstadr and peer.dstport */
  234.       u_char    leap;            /* receive */
  235. !     u_char    mode;            /* receive */
  236.       u_char    stratum;        /* receive */
  237.       u_char    ppoll;            /* receive */
  238.       u_char    hpoll;            /* poll update */
  239. --- 282,288 ----
  240.       int    sock;            /* index into sockets to derive
  241.                          peer.dstadr and peer.dstport */
  242.       u_char    leap;            /* receive */
  243. !     u_char    hmode;            /* receive */
  244.       u_char    stratum;        /* receive */
  245.       u_char    ppoll;            /* receive */
  246.       u_char    hpoll;            /* poll update */
  247. ***************
  248. *** 304,310 ****
  249.        * first order offsets
  250.        */
  251.       struct    filter {
  252. !         short samples;
  253.           double offset[PEER_SHIFT];
  254.           double delay[PEER_SHIFT];
  255.       } filter;            /* filter, clear */
  256. --- 302,308 ----
  257.        * first order offsets
  258.        */
  259.       struct    filter {
  260. !         short samples;        /* <<local>> */
  261.           double offset[PEER_SHIFT];
  262.           double delay[PEER_SHIFT];
  263.       } filter;            /* filter, clear */
  264.  
  265. Index: ntp_proto.c
  266. *** ntp_proto.c.old    Wed Mar 29 12:47:49 1989
  267. --- ntp_proto.c    Wed Mar 29 12:47:51 1989
  268. ***************
  269. *** 1,5 ****
  270.   #ifndef    lint
  271. ! static char *rcsid = "$Source: /usr/users/louie/ntp/RCS/ntp_proto.c,v $ $Revision: 3.4.1.3 $ $Date: 89/03/22 18:32:31 $";
  272.   #endif
  273.   
  274.   /*
  275. --- 1,5 ----
  276.   #ifndef    lint
  277. ! static char *rcsid = "$Source: /usr/users/louie/ntp/RCS/ntp_proto.c,v $ $Revision: 3.4.1.4 $ $Date: 89/03/29 12:29:10 $";
  278.   #endif
  279.   
  280.   /*
  281. ***************
  282. *** 10,15 ****
  283. --- 10,22 ----
  284.    *
  285.    *
  286.    * $Log:    ntp_proto.c,v $
  287. +  * Revision 3.4.1.4  89/03/29  12:29:10  louie
  288. +  * The variable 'mode' in the peer structure was renamed 'hmode'.  Add 
  289. +  * poll_update() calls in a few places per Mills.  The receive() procedure is
  290. +  * now table driven.  The poll_update procedure only randomized the timer
  291. +  * when the interval changes.  If we lose synchronization, don't zap sys.stratum.
  292. +  * Clean up the sanity_check() routine a bit.
  293. +  * 
  294.    * Revision 3.4.1.3  89/03/22  18:32:31  louie
  295.    * patch3: Use new RCS headers.
  296.    * 
  297. ***************
  298. *** 123,129 ****
  299.       struct ntpdata *pkt = &ntpframe;
  300.       int i;
  301.   
  302. !     pkt->status = sys.leap | NTPVERSION_1 | peer->mode;
  303.       pkt->stratum = sys.stratum;
  304.       pkt->ppoll = peer->hpoll;
  305.       pkt->precision = (char) sys.precision;
  306. --- 130,136 ----
  307.       struct ntpdata *pkt = &ntpframe;
  308.       int i;
  309.   
  310. !     pkt->status = sys.leap | NTPVERSION_1 | peer->hmode;
  311.       pkt->stratum = sys.stratum;
  312.       pkt->ppoll = peer->hpoll;
  313.       pkt->precision = (char) sys.precision;
  314. ***************
  315. *** 214,225 ****
  316.           peer->valid++;
  317.       else {
  318.           clock_filter(peer, 0.0, 0.0);    /* call with invalid values */
  319. !         if (peer == sys.peer) {
  320. !             select_clock();        /* and try to reselect clock */
  321. !             if (peer != sys.peer && sys.peer != NULL)
  322. !                 poll_update(sys.peer, NTP_MINPOLL);
  323. !         }
  324.       }
  325.       peer->timer = 1<<(MAX(MIN(peer->ppoll, MIN(peer->hpoll, NTP_MAXPOLL)),
  326.                      NTP_MINPOLL));
  327.   
  328. --- 221,231 ----
  329.           peer->valid++;
  330.       else {
  331.           clock_filter(peer, 0.0, 0.0);    /* call with invalid values */
  332. !         select_clock();        /* and try to reselect clock */
  333. !         if (sys.peer != NULL)
  334. !             poll_update(sys.peer, NTP_MINPOLL);
  335.       }
  336.       peer->timer = 1<<(MAX(MIN(peer->ppoll, MIN(peer->hpoll, NTP_MAXPOLL)),
  337.                      NTP_MINPOLL));
  338.   
  339. ***************
  340. *** 240,245 ****
  341. --- 246,267 ----
  342.       struct ntp_peer *peer;
  343.       int peer_mode;
  344.   
  345. + #define    ACT_ERROR    1
  346. + #define    ACT_RECV    2
  347. + #define    ACT_XMIT    3
  348. + #define    ACT_PKT        4
  349. +     static char actions[5][5] = {
  350. +  /*      Sym Act   Sym Pas    Client     Server     Broadcast  |Host /       */
  351. +  /*      --------   --------  --------   ---------  ---------  |    / Peer   */
  352. +  /*                                                            ------------  */
  353. +     {ACT_PKT,  ACT_PKT,   ACT_RECV,  ACT_XMIT,  ACT_XMIT},    /* Sym Act   */
  354. +     {ACT_PKT,  ACT_ERROR, ACT_RECV,  ACT_ERROR, ACT_ERROR},    /* Sym Pas   */
  355. +     {ACT_XMIT, ACT_XMIT,  ACT_ERROR, ACT_XMIT,  ACT_XMIT},    /* Client    */
  356. +     {ACT_PKT,  ACT_ERROR, ACT_RECV,  ACT_ERROR, ACT_ERROR},    /* Server    */
  357. +     {ACT_PKT,  ACT_ERROR, ACT_RECV,  ACT_ERROR, ACT_ERROR}};/* Broadcast */
  358.       /* if we're only going to support NTP Version 2 then this stuff
  359.          isn't necessary, right? */
  360.   
  361. ***************
  362. *** 277,283 ****
  363.           make_new_peer(peer);
  364.           peer->src = *dst;
  365.           peer->sock = sock;
  366. !         peer->mode = MODE_SYM_PAS;
  367.           clear(peer);
  368.       } else
  369.           peer = check_peer(dst, sock);
  370. --- 299,305 ----
  371.           make_new_peer(peer);
  372.           peer->src = *dst;
  373.           peer->sock = sock;
  374. !         peer->hmode = MODE_SYM_PAS;
  375.           clear(peer);
  376.       } else
  377.           peer = check_peer(dst, sock);
  378. ***************
  379. *** 292,302 ****
  380.           peer->src = *dst;
  381.           peer->sock = sock;    /* remember which socket we heard 
  382.                          this from */
  383. !         peer->mode = MODE_SYM_PAS;
  384.           clear(peer);
  385.           enqueue(&peer_list, peer);
  386.       }
  387.   
  388.   #ifdef    BROADCAST_NTP
  389.       /*
  390.        *  Input frame matched a funny broadcast peer;  these peers only
  391. --- 314,333 ----
  392.           peer->src = *dst;
  393.           peer->sock = sock;    /* remember which socket we heard 
  394.                          this from */
  395. !         peer->hmode = MODE_SYM_PAS;
  396.           clear(peer);
  397.           enqueue(&peer_list, peer);
  398.       }
  399.   
  400. +     /* 
  401. +      *  "pre-configured" peers are initially assigned a socket index of
  402. +      *  -1, which means we don't know which interface we'll use to talk
  403. +      *  to them.  Once the first reply comes back, we'll update the
  404. +      *  peer structure
  405. +      */
  406. +     if (peer->sock == -1)
  407. +         peer->sock = sock;
  408.   #ifdef    BROADCAST_NTP
  409.       /*
  410.        *  Input frame matched a funny broadcast peer;  these peers only
  411. ***************
  412. *** 313,406 ****
  413.       }
  414.   #endif    /* BROADCAST_NTP */
  415.   
  416. !     /* 
  417. !      *  "pre-configured" peers are initially assigned a socket index of
  418. !      *  -1, which means we don't know which interface we'll use to talk
  419. !      *  to them.  Once the first reply comes back, we'll update the
  420. !      *  peer structure
  421. !      */
  422. !     if (peer->sock == -1)
  423. !         peer->sock = sock;
  424.   
  425. !     switch (peer_mode) {
  426. !     case MODE_SYM_PAS:
  427. !         if (peer->mode == MODE_SYM_PAS)
  428. !             goto receive_MODE_BROADCAST;    /* forgive me! */
  429.   
  430. !         /* * * * * NOTE FALL THRU * * * * */
  431. !     case MODE_SYM_ACT:
  432. !         if (! STRMCMP(pkt->stratum, <=, sys.stratum)) {
  433. !             /*
  434. !              *  While not strictly in the spec, pre-configured
  435. !              *  peers will have their reachability kept, even 
  436. !              *  though they won't be selected.  We might as well
  437. !              *  since we've dedicated the resources to have these
  438. !              *  peers be persistant.
  439. !              */
  440. !             if (peer->flags & PEER_FL_CONFIG)
  441. !                 peer->reach |= 1;
  442. !             switch (peer->mode) {
  443. !             case MODE_SYM_ACT:
  444. !             case MODE_CLIENT:
  445. !             case MODE_BROADCAST:
  446. !                 process_packet(dst, pkt, tvp, peer);
  447. !                 break;
  448. !             default:
  449. !                 process_packet(dst, pkt, tvp, peer);
  450. !                 poll_update(peer, peer->ppoll);
  451. !                 transmit(peer);
  452. !             }                
  453.               break;
  454.           }
  455. !         /* * * * * NOTE FALL THRU * * * * */
  456.   
  457. !     case MODE_SERVER:
  458. !         peer->reach |= 1;
  459. !         process_packet(dst, pkt, tvp, peer);
  460. !         break;
  461. !     case MODE_CLIENT:
  462. !         if (peer->flags & PEER_FL_CONFIG)
  463. !             break;
  464. !         switch (peer->mode) {
  465. !         case MODE_SYM_ACT:
  466. !         case MODE_CLIENT:
  467. !         case MODE_BROADCAST:
  468.               process_packet(dst, pkt, tvp, peer);
  469.               break;
  470. -         default:
  471. -             peer->mode = MODE_SERVER;
  472. -             process_packet(dst, pkt, tvp, peer);
  473. -             poll_update(peer, peer->ppoll);
  474. -             transmit(peer);
  475.           }
  476. !         break;
  477. ! #ifdef    BROADCAST_NTP
  478. !     case MODE_BROADCAST:
  479. ! #endif
  480. !     receive_MODE_BROADCAST:    
  481. !         if (peer->flags & PEER_FL_CONFIG)
  482. !             break;
  483.           process_packet(dst, pkt, tvp, peer);
  484. !         if (peer != &dummy_peer)
  485. !             demobilize(&peer_list, peer);
  486.           break;
  487.   
  488. - #ifdef    DEBUG
  489.       default:
  490. !         if (debug)
  491. !             printf("Unknown mode %d for peer at %s\n",
  492. !                    peer_mode, inet_ntoa(dst->sin_addr));
  493. ! #endif
  494.       }
  495.   }
  496.   
  497.   /* 3.4.3 Packet procedure */
  498.   void
  499.   process_packet(dst, pkt, tvp, peer)
  500. --- 344,403 ----
  501.       }
  502.   #endif    /* BROADCAST_NTP */
  503.   
  504. ! #if    0
  505. !     if ((peer->flags & PEER_FL_AUTHENABLE) &&
  506. !         pkt->mac) {
  507. !         /* verify computed crypto-checksum */
  508. !     }
  509. ! #endif
  510.   
  511. ! #ifdef    DEBUG
  512. !     if (peer_mode < MODE_SYM_ACT || peer_mode > MODE_BROADCAST ||
  513. !         peer->hmode < MODE_SYM_ACT || peer->hmode > MODE_BROADCAST) {
  514. !         printf("Bogus peer_mode or peer->hmode\n");
  515. !         abort();
  516. !     }
  517. ! #endif
  518.   
  519. !     switch (actions[peer_mode - 1][peer->hmode - 1]) {
  520. !     case ACT_RECV:
  521. !         if (!(peer->flags & PEER_FL_CONFIG == 0 &&
  522. !               STRMCMP(pkt->stratum, >, sys.stratum))) {
  523. !             peer->reach |= 1;
  524. !             process_packet(dst, pkt, tvp, peer);
  525.               break;
  526.           }
  527. !         /* Note fall-through */
  528. !     case ACT_ERROR:
  529. !         if ((peer != &dummy_peer) && (peer->flags & PEER_FL_CONFIG))
  530. !             demobilize(peer);
  531. !         return;
  532.   
  533. !     case ACT_PKT:
  534. !         if (!((peer->flags & PEER_FL_CONFIG == 0) &&
  535. !             STRMCMP(pkt->stratum, >, sys.stratum))) {
  536. !             peer->reach |= 1;
  537.               process_packet(dst, pkt, tvp, peer);
  538.               break;
  539.           }
  540. !         /* note fall-through */
  541. !     case ACT_XMIT:
  542.           process_packet(dst, pkt, tvp, peer);
  543. !         poll_update(peer, peer->ppoll);
  544. !         transmit(peer);
  545.           break;
  546.   
  547.       default:
  548. !         abort();
  549.       }
  550.   }
  551.   
  552. + #undef    ACT_ERROR
  553. + #undef    ACT_RECV
  554. + #undef    ACT_XMIT
  555. + #undef    ACT_PKT
  556.   /* 3.4.3 Packet procedure */
  557.   void
  558.   process_packet(dst, pkt, tvp, peer)
  559. ***************
  560. *** 508,518 ****
  561.   {
  562.       double temp;
  563.       extern int adj_logical();
  564. -     struct ntp_peer *old_selection = sys.peer;
  565.   
  566.       select_clock();
  567. !     if (old_selection != sys.peer && sys.peer != NULL)
  568.           poll_update(sys.peer, NTP_MINPOLL);
  569.   
  570.       /*
  571. --- 505,513 ----
  572.   {
  573.       double temp;
  574.       extern int adj_logical();
  575.   
  576.       select_clock();
  577. !     if (sys.peer != NULL)
  578.           poll_update(sys.peer, NTP_MINPOLL);
  579.   
  580.       /*
  581. ***************
  582. *** 631,637 ****
  583.       peer->estdisp = PEER_MAXDISP;
  584.       for (i = 0; i < NTP_WINDOW; i++)
  585.           peer->filter.offset[i] = 0.0;
  586. !     peer->filter.samples = 0;
  587.       peer->reach = 0;
  588.       peer->valid = 0;
  589.       peer->org.int_part = peer->org.fraction = 0;
  590. --- 626,632 ----
  591.       peer->estdisp = PEER_MAXDISP;
  592.       for (i = 0; i < NTP_WINDOW; i++)
  593.           peer->filter.offset[i] = 0.0;
  594. !     peer->filter.samples = 0;    /* Implementation specific */
  595.       peer->reach = 0;
  596.       peer->valid = 0;
  597.       peer->org.int_part = peer->org.fraction = 0;
  598. ***************
  599. *** 639,644 ****
  600. --- 634,641 ----
  601.       peer->xmt.int_part = peer->xmt.fraction = 0;
  602.       poll_update(peer, NTP_MINPOLL);
  603.       select_clock();
  604. +     if (sys.peer != NULL)
  605. +         poll_update(sys.peer, NTP_MINPOLL);
  606.   }
  607.   
  608.   
  609. ***************
  610. *** 660,665 ****
  611. --- 657,666 ----
  612.       interval = 1 << (MAX(MIN(peer->ppoll, MIN(peer->hpoll, NTP_MAXPOLL)),
  613.                  NTP_MINPOLL));
  614.   
  615. +     if (interval == peer->timer)
  616. +         return;
  617. +     /* only randomize when poll interval changes */
  618.       if (interval < peer->timer)
  619.           peer->timer = interval;
  620.   
  621. ***************
  622. *** 745,752 ****
  623.   
  624.           peer->estdelay = delay[0];
  625.           peer->estoffset = offset[0];
  626. !     } else
  627. !         peer->estoffset = peer->estdelay = 0.0;
  628.   
  629.       temp = 0.0;
  630.       w = 1.0;
  631. --- 746,752 ----
  632.   
  633.           peer->estdelay = delay[0];
  634.           peer->estoffset = offset[0];
  635. !     }
  636.   
  637.       temp = 0.0;
  638.       w = 1.0;
  639. ***************
  640. *** 821,828 ****
  641.               printf("select_clock: no candidates\n");
  642.   #endif
  643.           sys.peer = NULL;
  644. !         sys.stratum = 0;
  645. !         sys.refid = htonl('N'<<24 | 'O'<<16 | 'N'<<8 | 'E');
  646.           return;
  647.       }
  648.   
  649. --- 821,832 ----
  650.               printf("select_clock: no candidates\n");
  651.   #endif
  652.           sys.peer = NULL;
  653. !         /*
  654. !          * leave sys.stratum and sys.refid intact after losing 
  655. !          * reachability to all clocks.  After 24 hours, we'll
  656. !          * set the alarm condition if we didn't get any clock
  657. !          * updates.
  658. !          */
  659.           return;
  660.       }
  661.   
  662. ***************
  663. *** 984,1009 ****
  664.           printf("Checking peer %s stratum %d\n",
  665.                  inet_ntoa(peer->src.sin_addr), peer->stratum);
  666.   #endif
  667. !     /* are we allowed to sync to this clock? */
  668. !     if ((peer->flags & PEER_FL_SYNC) == 0)
  669.           return(0);
  670.   
  671. !     /* is peer reachable?        XXX */
  672. !     if (peer->reach == 0)
  673.           return(0);
  674.   
  675. !     /* is peer synchronized? */
  676. !     if (peer->leap == ALARM)
  677. !         return(0);
  678.   
  679. -     /* is peer worse off than us?    XXX */
  680. -     if (STRMCMP(peer->stratum, >, sys.stratum) ||
  681. -         (peer->stratum >= MAXSTRATUM))
  682. -         return(0);
  683. -     /* 4.2 "if peer.stratum is greater than one (synchronized via NTP),
  684. -        peer.refid must not match peer.dstadr" */
  685.       if (peer->stratum > 1) {
  686.           register int i;
  687.           for (i = 1; i < nintf; i++)
  688. --- 988,1005 ----
  689.           printf("Checking peer %s stratum %d\n",
  690.                  inet_ntoa(peer->src.sin_addr), peer->stratum);
  691.   #endif
  692. !     /* Sanity check 0. ?? */
  693. !     if (!(peer->flags & PEER_FL_CONFIG))
  694.           return(0);
  695.   
  696. !     /* Sanity check 1. */
  697. !     if (peer->stratum <= 0 || peer->stratum >= NTP_INFIN)
  698.           return(0);
  699.   
  700. !     /* Sanity check 2.
  701. !        if peer.stratum is greater than one (synchronized via NTP),
  702. !        peer.refid must not match peer.dstadr */
  703.   
  704.       if (peer->stratum > 1) {
  705.           register int i;
  706.           for (i = 1; i < nintf; i++)
  707. ***************
  708. *** 1011,1035 ****
  709.                   return (0);
  710.       }
  711.   
  712. !     /* 
  713. !        4.2. "Another check requires that both peer.estdelay and
  714.          peer.estdisp to be less than NTP_MAXWGT, which insures that the
  715. !        filter register at least half full, yet avoids using data
  716. !        from very noisy associations or broken implementations."
  717. !     */
  718.       if (peer->estdisp > (float)NTP_MAXWGT || 
  719.           peer->estdelay > (float)NTP_MAXWGT)
  720.           return(0);
  721.   
  722. !     /*  4.2 "A third check requires that the interval since the peer
  723. !         clock was last updated be less than NTP_MAXAGS */
  724.   
  725. !     if ((ul_fixed_to_double(&peer->org)
  726.            - ul_fixed_to_double(&peer->reftime)) >= NTP_MAXAGE)
  727. -         return(0);
  728. -     /* is dispersion reasonable? */
  729. -     if (s_fixed_to_double(&peer->dispersion) > PEER_THRESHOLD)
  730.           return(0);
  731.   
  732.   #ifdef    DEBUG
  733. --- 1007,1030 ----
  734.                   return (0);
  735.       }
  736.   
  737. !     /* Sanity check 3.
  738. !        Both peer.estdelay and
  739.          peer.estdisp to be less than NTP_MAXWGT, which insures that the
  740. !        filter register at least half full, yet avoids using data from
  741. !        very noisy associations or broken implementations.      */
  742.       if (peer->estdisp > (float)NTP_MAXWGT || 
  743.           peer->estdelay > (float)NTP_MAXWGT)
  744.           return(0);
  745.   
  746. !     /*  Sanity check 4.
  747. !         The peer clock must be synchronized... and the interval since
  748. !         the peer clock was last updated satisfy
  749.   
  750. !         peer.org - peer.reftime < NTP.MAXAGS
  751. !      */
  752. !     if (peer->leap == ALARM ||
  753. !         (ul_fixed_to_double(&peer->org)
  754.            - ul_fixed_to_double(&peer->reftime)) >= NTP_MAXAGE)
  755.           return(0);
  756.   
  757.   #ifdef    DEBUG
  758.  
  759. Index: ntpd.c
  760. *** ntpd.c.old    Wed Mar 29 12:48:00 1989
  761. --- ntpd.c    Wed Mar 29 12:48:03 1989
  762. ***************
  763. *** 1,9 ****
  764.   #ifndef    lint
  765. ! static char *rcsid = "$Source: /usr/users/louie/ntp/RCS/ntpd.c,v $ $Revision: 3.4.1.3 $ $Date: 89/03/22 18:29:41 $";
  766.   #endif    lint
  767.   
  768.   /*
  769.    *  $Log:    ntpd.c,v $
  770.    * Revision 3.4.1.3  89/03/22  18:29:41  louie
  771.    * patch3: Use new RCS headers.
  772.    * 
  773. --- 1,13 ----
  774.   #ifndef    lint
  775. ! static char *rcsid = "$Source: /usr/users/louie/ntp/RCS/ntpd.c,v $ $Revision: 3.4.1.4 $ $Date: 89/03/29 12:30:46 $";
  776.   #endif    lint
  777.   
  778.   /*
  779.    *  $Log:    ntpd.c,v $
  780. +  * Revision 3.4.1.4  89/03/29  12:30:46  louie
  781. +  * peer->mode has been renamed peer->hmode.  Drop PEER_FL_SYNC since the
  782. +  * PEER_FL_CONFIG flag means much the same thing.
  783. +  * 
  784.    * Revision 3.4.1.3  89/03/22  18:29:41  louie
  785.    * patch3: Use new RCS headers.
  786.    * 
  787. ***************
  788. *** 238,249 ****
  789.           setlogmask(LOG_UPTO(LOG_INFO));
  790.   #endif    /* LOG_DAEMON */
  791.   
  792. !     syslog(LOG_NOTICE, "%s version $Revision: 3.4.1.3 $", prog_name);
  793.       syslog(LOG_NOTICE, "patchlevel %d", PATCHLEVEL);
  794.   
  795.   #ifdef    DEBUG
  796.       if (debug)
  797. !         printf("%s version $Revision: 3.4.1.3 $ patchlevel %d\n",
  798.                  prog_name, PATCHLEVEL);
  799.   #endif
  800.       (void) setpriority(PRIO_PROCESS, 0, -10);
  801. --- 242,253 ----
  802.           setlogmask(LOG_UPTO(LOG_INFO));
  803.   #endif    /* LOG_DAEMON */
  804.   
  805. !     syslog(LOG_NOTICE, "%s version $Revision: 3.4.1.4 $", prog_name);
  806.       syslog(LOG_NOTICE, "patchlevel %d", PATCHLEVEL);
  807.   
  808.   #ifdef    DEBUG
  809.       if (debug)
  810. !         printf("%s version $Revision: 3.4.1.4 $ patchlevel %d\n",
  811.                  prog_name, PATCHLEVEL);
  812.   #endif
  813.       (void) setpriority(PRIO_PROCESS, 0, -10);
  814. ***************
  815. *** 455,461 ****
  816.       peer->src.sin_family = AF_INET;
  817.       peer->src.sin_port = 0;
  818.       peer->src.sin_addr.s_addr = 0;
  819. !     peer->mode = MODE_SYM_PAS;    /* default: symmetric passive mode */
  820.       peer->flags = 0;
  821.       peer->timer = 1 << NTP_MINPOLL;
  822.       peer->stopwatch = 0;
  823. --- 459,465 ----
  824.       peer->src.sin_family = AF_INET;
  825.       peer->src.sin_port = 0;
  826.       peer->src.sin_addr.s_addr = 0;
  827. !     peer->hmode = MODE_SYM_PAS;    /* default: symmetric passive mode */
  828.       peer->flags = 0;
  829.       peer->timer = 1 << NTP_MINPOLL;
  830.       peer->stopwatch = 0;
  831. ***************
  832. *** 469,475 ****
  833.       peer->filter.samples = 0;
  834.       for (i = 0; i < NTP_WINDOW; i++) {
  835.           peer->filter.offset[i] = 0.0;
  836. !         peer->filter.delay[i] = NTP_MAXDELAY;
  837.       }
  838.       peer->pkt_sent = 0;
  839.       peer->pkt_rcvd = 0;
  840. --- 473,479 ----
  841.       peer->filter.samples = 0;
  842.       for (i = 0; i < NTP_WINDOW; i++) {
  843.           peer->filter.offset[i] = 0.0;
  844. !         peer->filter.delay[i] = 0.0;
  845.       }
  846.       peer->pkt_sent = 0;
  847.       peer->pkt_rcvd = 0;
  848. ***************
  849. *** 615,621 ****
  850.           }
  851.   #endif
  852.           next = peer->next;
  853. !         if (peer->reach != 0 || peer->mode != MODE_SERVER) {
  854.               peer->stopwatch +=(1<<CLOCK_ADJ);
  855.               if (peer->timer <= peer->stopwatch) {
  856.                   transmit(peer);
  857. --- 619,625 ----
  858.           }
  859.   #endif
  860.           next = peer->next;
  861. !         if (peer->reach != 0 || peer->hmode != MODE_SERVER) {
  862.               peer->stopwatch +=(1<<CLOCK_ADJ);
  863.               if (peer->timer <= peer->stopwatch) {
  864.                   transmit(peer);
  865. ***************
  866. *** 663,669 ****
  867.   {
  868.       struct sockaddr_in sin;
  869.       char ref_clock[5];
  870. !     char name[MAXNAMELENGTH + 1];
  871.       FILE *fp;
  872.       int error = FALSE, c;
  873.       struct ntp_peer *peer;
  874. --- 667,673 ----
  875.   {
  876.       struct sockaddr_in sin;
  877.       char ref_clock[5];
  878. !     char name[81];
  879.       FILE *fp;
  880.       int error = FALSE, c;
  881.       struct ntp_peer *peer;
  882. ***************
  883. *** 750,756 ****
  884.               }
  885.               make_new_peer(peer);
  886.               peer->flags = PEER_FL_BCAST;
  887. !             peer->mode = MODE_BROADCAST;
  888.               peer->src = addrs[i].bcast;
  889.               peer->sock = i;
  890.   #endif    /* BROADCAST_NTP */
  891. --- 754,760 ----
  892.               }
  893.               make_new_peer(peer);
  894.               peer->flags = PEER_FL_BCAST;
  895. !             peer->hmode = MODE_BROADCAST;
  896.               peer->src = addrs[i].bcast;
  897.               peer->sock = i;
  898.   #endif    /* BROADCAST_NTP */
  899. ***************
  900. *** 791,811 ****
  901.                           peer->flags = PEER_FL_CONFIG;
  902.                           switch (mode) {
  903.                           case MODE_SYM_ACT:    /* "peer" */
  904. !                             peer->mode = MODE_SYM_ACT;
  905. !                             /* mark peer as sync-able */
  906. !                             peer->flags |= PEER_FL_SYNC;
  907.                               peer->stopwatch = stagger;
  908.                               stagger += (1<<CLOCK_ADJ);
  909.                               break;
  910.                           case MODE_CLIENT:    /* "server" */
  911. !                             peer->mode = MODE_CLIENT;
  912. !                             peer->flags |= PEER_FL_SYNC;
  913.                               peer->stopwatch = stagger;
  914.                               stagger += (1<<CLOCK_ADJ);
  915.                               break;
  916.                           case MODE_SYM_PAS:    /* "passive" */
  917. !                             peer->mode = MODE_SYM_PAS;
  918. !                             peer->flags |= PEER_FL_SYNC;
  919.                               break;
  920.                           default:
  921.                               printf("can't happen\n");
  922. --- 795,811 ----
  923.                           peer->flags = PEER_FL_CONFIG;
  924.                           switch (mode) {
  925.                           case MODE_SYM_ACT:    /* "peer" */
  926. !                             peer->hmode = MODE_SYM_ACT;
  927.                               peer->stopwatch = stagger;
  928.                               stagger += (1<<CLOCK_ADJ);
  929.                               break;
  930.                           case MODE_CLIENT:    /* "server" */
  931. !                             peer->hmode = MODE_CLIENT;
  932.                               peer->stopwatch = stagger;
  933.                               stagger += (1<<CLOCK_ADJ);
  934.                               break;
  935.                           case MODE_SYM_PAS:    /* "passive" */
  936. !                             peer->hmode = MODE_SYM_PAS;
  937.                               break;
  938.                           default:
  939.                               printf("can't happen\n");
  940. ***************
  941. *** 821,827 ****
  942.                                      inet_ntoa(peer->src.sin_addr),
  943.                                      ntohs(peer->src.sin_port),
  944.                                      peer->src.sin_family,
  945. !                                    peer->mode);
  946.   #endif
  947.                       }
  948.                   } else {
  949. --- 821,827 ----
  950.                                      inet_ntoa(peer->src.sin_addr),
  951.                                      ntohs(peer->src.sin_port),
  952.                                      peer->src.sin_family,
  953. !                                    peer->hmode);
  954.   #endif
  955.                       }
  956.                   } else {
  957.  
  958. Index: ntpdc.c
  959. *** ntpdc.c.old    Wed Mar 29 12:48:09 1989
  960. --- ntpdc.c    Wed Mar 29 12:48:11 1989
  961. ***************
  962. *** 1,9 ****
  963.   #ifndef    lint
  964. ! static char *RCSid = "$Source: /usr/users/louie/ntp/RCS/ntpdc.c,v $ $Revision: 3.4.1.3 $ $Date: 89/03/22 18:29:53 $";
  965.   #endif
  966.   
  967.   /*
  968.    * $Log:    ntpdc.c,v $
  969.    * Revision 3.4.1.3  89/03/22  18:29:53  louie
  970.    * patch3: Use new RCS headers.
  971.    * 
  972. --- 1,13 ----
  973.   #ifndef    lint
  974. ! static char *RCSid = "$Source: /usr/users/louie/ntp/RCS/ntpdc.c,v $ $Revision: 3.4.1.4 $ $Date: 89/03/29 12:41:56 $";
  975.   #endif
  976.   
  977.   /*
  978.    * $Log:    ntpdc.c,v $
  979. +  * Revision 3.4.1.4  89/03/29  12:41:56  louie
  980. +  * Check for success sending query before trying to listen for answers.  Will 
  981. +  * catch case of no server running and an ICMP port unreachable being returned.
  982. +  * 
  983.    * Revision 3.4.1.3  89/03/22  18:29:53  louie
  984.    * patch3: Use new RCS headers.
  985.    * 
  986. ***************
  987. *** 130,135 ****
  988. --- 134,140 ----
  989.       }
  990.       if (argc > 1)
  991.           printf("--- %s ---\n", *argv);
  992.       while (argc > 0) {
  993.           /*
  994.            * Get a new socket each time - this will cause us to ignore
  995. ***************
  996. *** 145,152 ****
  997.               fprintf(stderr, "setsockopt SO_RCVBUF\n");
  998.           }
  999.   #endif
  1000. !         query(*argv);
  1001. !         answer();
  1002.           close(s);
  1003.           argv++;
  1004.           if (argc-- > 1)
  1005. --- 150,157 ----
  1006.               fprintf(stderr, "setsockopt SO_RCVBUF\n");
  1007.           }
  1008.   #endif
  1009. !         if (query(*argv))
  1010. !             answer(*argv);
  1011.           close(s);
  1012.           argv++;
  1013.           if (argc-- > 1)
  1014. ***************
  1015. *** 155,161 ****
  1016.   
  1017.   }
  1018.   
  1019. ! answer() {
  1020.       register struct ntpinfo *msg = (struct ntpinfo *) packet;
  1021.       register struct clockinfo *n;
  1022.       struct sockaddr_in from;
  1023. --- 160,168 ----
  1024.   
  1025.   }
  1026.   
  1027. ! answer(host)
  1028. !     char *host;
  1029. ! {
  1030.       register struct ntpinfo *msg = (struct ntpinfo *) packet;
  1031.       register struct clockinfo *n;
  1032.       struct sockaddr_in from;
  1033. ***************
  1034. *** 184,192 ****
  1035.                    (struct sockaddr *)&from, &fromlen)) <= 0) {
  1036.               if (cc == 0 || errno == EINTR)
  1037.                   continue;
  1038. !             perror("recvfrom");
  1039.               (void) close(s);
  1040. !             exit(1);
  1041.           }
  1042.           FD_SET(s, &bits);
  1043.   
  1044. --- 191,200 ----
  1045.                    (struct sockaddr *)&from, &fromlen)) <= 0) {
  1046.               if (cc == 0 || errno == EINTR)
  1047.                   continue;
  1048. !             fflush(stdout);
  1049. !             perror(host);
  1050.               (void) close(s);
  1051. !             return;
  1052.           }
  1053.           FD_SET(s, &bits);
  1054.   
  1055. ***************
  1056. *** 228,234 ****
  1057.           printf("Timed out waiting for replies\n");
  1058.   }
  1059.   
  1060.   query(host)
  1061.       char *host;
  1062.   {
  1063. --- 236,242 ----
  1064.           printf("Timed out waiting for replies\n");
  1065.   }
  1066.   
  1067. ! int
  1068.   query(host)
  1069.       char *host;
  1070.   {
  1071. ***************
  1072. *** 246,252 ****
  1073.           hp = gethostbyname(host);
  1074.           if (hp == 0) {
  1075.               fprintf(stderr,"%s: unknown\n", host);
  1076. !             exit(1);
  1077.           }
  1078.           bcopy(hp->h_addr, (char *) &watcher.sin_addr, hp->h_length);
  1079.       }
  1080. --- 254,260 ----
  1081.           hp = gethostbyname(host);
  1082.           if (hp == 0) {
  1083.               fprintf(stderr,"%s: unknown\n", host);
  1084. !             return 0;
  1085.           }
  1086.           bcopy(hp->h_addr, (char *) &watcher.sin_addr, hp->h_length);
  1087.       }
  1088. ***************
  1089. *** 260,271 ****
  1090.       msg->stratum = INFO_QUERY;
  1091.       if (connect(s, (struct sockaddr *) &watcher, sizeof(watcher))) {
  1092.           perror("connect");
  1093. !         exit(1);
  1094.       }
  1095.       if (send(s, packet, sizeof(struct ntpdata), 0) < 0) {
  1096.           perror("send");
  1097. !         exit(2);
  1098.       }
  1099.   }
  1100.   
  1101.   timeout()
  1102. --- 268,280 ----
  1103.       msg->stratum = INFO_QUERY;
  1104.       if (connect(s, (struct sockaddr *) &watcher, sizeof(watcher))) {
  1105.           perror("connect");
  1106. !         return 0;
  1107.       }
  1108.       if (send(s, packet, sizeof(struct ntpdata), 0) < 0) {
  1109.           perror("send");
  1110. !         return 0;
  1111.       }
  1112. +     return 1;
  1113.   }
  1114.   
  1115.   timeout()
  1116. ***************
  1117. *** 290,296 ****
  1118.       del = (long) ntohl(n->estdelay);    /* leave in milliseconds */
  1119.       off = (long) ntohl(n->estoffset);    /* leave in milliseconds */
  1120.       c = ' ';
  1121. !     if (ntohs(n->flags))
  1122.           c = '-';        /* mark pre-configured */
  1123.       if (ntohs(n->flags) & PEER_FL_SELECTED)
  1124.           c = '*';        /* mark peer selection */
  1125. --- 299,305 ----
  1126.       del = (long) ntohl(n->estdelay);    /* leave in milliseconds */
  1127.       off = (long) ntohl(n->estoffset);    /* leave in milliseconds */
  1128.       c = ' ';
  1129. !     if (ntohs(n->flags) & PEER_FL_CONFIG)
  1130.           c = '-';        /* mark pre-configured */
  1131.       if (ntohs(n->flags) & PEER_FL_SELECTED)
  1132.           c = '*';        /* mark peer selection */
  1133. ***************
  1134. *** 331,339 ****
  1135.              ntohs(n->flags),
  1136.              n->leap);
  1137.       if (n->stratum == 1 || n->stratum == 0) {
  1138. !         u_long TmP;
  1139. !         (void) strncpy(ref_clock, (char *) &TmP, 4);
  1140.           ref_clock[4] = '\0';
  1141.           printf("Reference clock ID: %s", ref_clock);
  1142.       } else {
  1143. --- 340,346 ----
  1144.              ntohs(n->flags),
  1145.              n->leap);
  1146.       if (n->stratum == 1 || n->stratum == 0) {
  1147. !         (void) strncpy(ref_clock, (char *) &n->refid, 4);
  1148.           ref_clock[4] = '\0';
  1149.           printf("Reference clock ID: %s", ref_clock);
  1150.       } else {
  1151.  
  1152. Index: ntpsubs.c
  1153. *** ntpsubs.c.old    Wed Mar 29 12:48:14 1989
  1154. --- ntpsubs.c    Wed Mar 29 12:48:15 1989
  1155. ***************
  1156. *** 1,9 ****
  1157.   #ifndef    lint
  1158. ! static char *RCSid = "$Source: /usr/users/louie/ntp/RCS/ntpsubs.c,v $ $Revision: 3.4.1.1 $ $Date: 89/03/22 18:32:19 $";
  1159.   #endif    lint
  1160.   
  1161.   /*
  1162.    *  $Log:    ntpsubs.c,v $
  1163.    * Revision 3.4.1.1  89/03/22  18:32:19  louie
  1164.    * patch3: Use new RCS headers.
  1165.    * 
  1166. --- 1,13 ----
  1167.   #ifndef    lint
  1168. ! static char *RCSid = "$Source: /usr/users/louie/ntp/RCS/ntpsubs.c,v $ $Revision: 3.4.1.2 $ $Date: 89/03/29 12:46:02 $";
  1169.   #endif    lint
  1170.   
  1171.   /*
  1172.    *  $Log:    ntpsubs.c,v $
  1173. +  * Revision 3.4.1.2  89/03/29  12:46:02  louie
  1174. +  * Check for success sending query before trying to listen for answers.  Will 
  1175. +  * catch case of no server running and an ICMP port unreachable being returned.
  1176. +  * 
  1177.    * Revision 3.4.1.1  89/03/22  18:32:19  louie
  1178.    * patch3: Use new RCS headers.
  1179.    * 
  1180. ***************
  1181. *** 181,187 ****
  1182.       results in the value 2^31.  Neither 4.2bsd nor VMS have this
  1183.       problem.  Reported it to Bob O'Brien of SMI
  1184.   */
  1185. ! #ifdef    sun
  1186.   tstamp(stampp, tvp)
  1187.       struct l_fixedpt *stampp;
  1188.       struct timeval *tvp;
  1189. --- 185,191 ----
  1190.       results in the value 2^31.  Neither 4.2bsd nor VMS have this
  1191.       problem.  Reported it to Bob O'Brien of SMI
  1192.   */
  1193. ! #ifdef    SUN_FLT_BUG
  1194.   tstamp(stampp, tvp)
  1195.       struct l_fixedpt *stampp;
  1196.       struct timeval *tvp;
  1197. ***************
  1198. *** 202,208 ****
  1199.       stampp->int_part = ntohl((u_long) (JAN_1970 + tvp->tv_sec));
  1200.       stampp->fraction = ntohl((u_long) ((float) tvp->tv_usec * 4294.967295));
  1201.   }
  1202. ! #endif    sun
  1203.   
  1204.   /*
  1205.    * ntoa is similar to inet_ntoa, but cycles through a set of 8 buffers
  1206. --- 206,212 ----
  1207.       stampp->int_part = ntohl((u_long) (JAN_1970 + tvp->tv_sec));
  1208.       stampp->fraction = ntohl((u_long) ((float) tvp->tv_usec * 4294.967295));
  1209.   }
  1210. ! #endif
  1211.   
  1212.   /*
  1213.    * ntoa is similar to inet_ntoa, but cycles through a set of 8 buffers
  1214.  
  1215. Index: stat.pl
  1216. Prereq: 3.4.1.2
  1217. *** stat.pl.old    Wed Mar 29 12:48:18 1989
  1218. --- stat.pl    Wed Mar 29 12:48:19 1989
  1219. ***************
  1220. *** 1,9 ****
  1221.   #!/usr/bin/perl  
  1222. ! # $Source: /usr/users/louie/ntp/RCS/stat.pl,v $ $Revision: 3.4.1.2 $ $Date: 89/03/22 18:32:28 $
  1223.   #
  1224.   #  Make plots from ntpd syslog messages.  Invoked as:
  1225.   #
  1226. ! #   stat.pl [-o outputfile] [-i interval] [-t termtype] [-S] < logmessages
  1227.   #
  1228.   #  Where interval is the number of hours per plot, default is all data on
  1229.   #  on set of plots.
  1230. --- 1,9 ----
  1231.   #!/usr/bin/perl  
  1232. ! # $Source: /usr/users/louie/ntp/RCS/stat.pl,v $ $Revision: 3.4.1.3 $ $Date: 89/03/29 12:47:32 $
  1233.   #
  1234.   #  Make plots from ntpd syslog messages.  Invoked as:
  1235.   #
  1236. ! #   stat.pl [-o outputfile] [-i interval] [-t termtype] [-S] [-l] < logmessages
  1237.   #
  1238.   #  Where interval is the number of hours per plot, default is all data on
  1239.   #  on set of plots.
  1240. ***************
  1241. *** 14,19 ****
  1242. --- 14,21 ----
  1243.   #  output file is the name of the file which will receive plot data.  The
  1244.   #  default is "stats.plot".
  1245.   #
  1246. + #  The -l option will also create log scale plots.
  1247. + #
  1248.   #  The -S option will "save" the intermedite data files, which are normally
  1249.   #  deleted.
  1250.   #
  1251. ***************
  1252. *** 47,56 ****
  1253.   $clocks = 1;
  1254.   $clk{'UNSYNCED'} = 0;
  1255.   
  1256. ! do Getopt('tiSo');
  1257.   
  1258.   if ($opt_h) {
  1259. !    die "Usage: $scriptfile [-o outputfile] [-i interval] [-t termtype] [-S] < logmessages\n";
  1260.   }
  1261.   
  1262.   if ($opt_t) {
  1263. --- 49,58 ----
  1264.   $clocks = 1;
  1265.   $clk{'UNSYNCED'} = 0;
  1266.   
  1267. ! do Getopt('tio');
  1268.   
  1269.   if ($opt_h) {
  1270. !    die "Usage: $scriptfile [-o outputfile] [-i interval] [-t termtype] [-l] [-S] < logmessages\n";
  1271.   }
  1272.   
  1273.   if ($opt_t) {
  1274. ***************
  1275. *** 92,98 ****
  1276.               $clk{$in[8]} = $clocks++;
  1277.           }
  1278.           $t = $t - $start;
  1279. !         printf CLK "%f %f\n",$t,$clk{$in[8]};
  1280.   
  1281.       }
  1282.       if (/.* ntpd\[[0-9]*\]: adjust:/) {
  1283. --- 94,100 ----
  1284.               $clk{$in[8]} = $clocks++;
  1285.           }
  1286.           $t = $t - $start;
  1287. !         print CLK $t,$clk{$in[8]},"\n";
  1288.   
  1289.       }
  1290.       if (/.* ntpd\[[0-9]*\]: adjust:/) {
  1291. ***************
  1292. *** 113,120 ****
  1293.           # offset=11 drift=13 compliance=15
  1294.   
  1295.           print OFF $t, " ", $in[11],"\n";
  1296. !         print DRIFT $t," ",$in[13],"\n";
  1297. !         print COMP $t," ",$in[15],"\n";
  1298.       }
  1299.   }
  1300.   
  1301. --- 115,129 ----
  1302.           # offset=11 drift=13 compliance=15
  1303.   
  1304.           print OFF $t, " ", $in[11],"\n";
  1305. !         #
  1306. !         #  Scale the drift compensation by 256.0 to convert to PPM.
  1307. !         #
  1308. !         print DRIFT $t," ", $in[13]/256.0, "\n";
  1309. !         #
  1310. !         #  Scale compliance by T (2**18)
  1311. !         #
  1312. !         print COMP $t," ",$in[15] * 2**18, "\n";
  1313.       }
  1314.   }
  1315.   
  1316. ***************
  1317. *** 123,129 ****
  1318.   } else {
  1319.       $last = int($t);
  1320.   }
  1321. ! printf "%d records spanning %4.2f hours.\n", $recs, $t;
  1322.   
  1323.   close OFF;
  1324.   close DRIFT;
  1325. --- 132,138 ----
  1326.   } else {
  1327.       $last = int($t);
  1328.   }
  1329. ! print "$recs records spanning %t hours.\n";
  1330.   
  1331.   close OFF;
  1332.   close DRIFT;
  1333. ***************
  1334. *** 169,174 ****
  1335. --- 178,188 ----
  1336.       print TMP "set autoscale\n";
  1337.       print TMP "plot [$start:$end] ",'"stats.drift"'," with lines\n";
  1338.       print TMP "plot [$start:$end] ",'"stats.comp"'," with lines\n";
  1339. +     if ($opt_l) {
  1340. +         print TMP "set logscale y\n";
  1341. +         print TMP "plot [$start:$end] ",'"stats.comp"'," with lines\n";
  1342. +         print TMP "set nologscale\n";
  1343. +     }
  1344.       print TMP "plot [$start:$end] [-0.1:0.1] ",
  1345.           '"stats.off"'," with lines\n";
  1346.       print TMP "plot [$start:$end] [0:$clocks]",
  1347. ***************
  1348. *** 192,198 ****
  1349.       unlink "stats.clk";
  1350.   }
  1351.   
  1352. ! ;# $Header: /usr/users/louie/ntp/RCS/stat.pl,v 3.4.1.2 89/03/22 18:32:28 louie Exp $
  1353.   
  1354.   ;# Process single-character switches with switch clustering.  Pass one argument
  1355.   ;# which is a string containing all switches that take an argument.  For each
  1356. --- 206,212 ----
  1357.       unlink "stats.clk";
  1358.   }
  1359.   
  1360. ! ;# $Header: /usr/users/louie/ntp/RCS/stat.pl,v 3.4.1.3 89/03/29 12:47:32 louie Exp Locker: louie $
  1361.   
  1362.   ;# Process single-character switches with switch clustering.  Pass one argument
  1363.   ;# which is a string containing all switches that take an argument.  For each
  1364.